#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<vector>
using namespace std;

class A
{
public:
    virtual void func(int val = 1) { std::cout << "A->" << val << std::endl; }
    virtual void test() { func(); }
};

class B : public A
{
public:
    void func(int val = 0) { std::cout << "B->" << val << std::endl; }
};

class Solution {
public:
    bool isUnique(string astr) {
        int ret = 0;
        for (auto ch : astr)
        {
            int tmp = ch - 'a';
            if ((ret >> tmp) & 1)   return false;
            else    ret |= 1 << tmp;
        }
        return true;
    }

    int missingNumber(vector<int>& nums) {
        int ret = nums.size();
        for (int i = 0; i < nums.size(); i++)
        {
            ret ^= i;
            ret ^= nums[i];
        }
        return ret;
    }

    int getSum(int a, int b) {
        int sum = 0, flag = 0;
        for (int i = 0; i < 32; i++)
        {
            if ((a >> i) & (b >> i) & 1)
            {
                sum |= flag << i;
                flag = 1;
            }
            else if (((a >> i) | (b >> i)) == 0)
            {
                sum |= flag << i;
                flag = 0;
            }
            else
            {
                if (flag)    flag = 1;
                else
                {
                    sum |= 1 << i;
                    flag = 0;
                }
            }
        }
        return sum;
    }

    int getSum2(int a, int b) {
        int ret = a;
        while (b)
        {
            ret ^= b;
            b = (a & b) << 1;
            a = ret;
        }
        return ret;
    }
};

int main(int argc, char* argv[])
{
    Solution s;
    s.getSum(2, 3);
}